package com.qiyu.mall.user.provider.service;

import com.qiyu.mall.user.interfaces.dto.CommunityAssociateDTO;
import com.qiyu.mall.user.interfaces.service.CommunityAssociateService;
import com.qiyu.mall.user.provider.dao.CommunityAssociateDao;
import com.qiyu.mall.user.provider.entity.CommunityAssociatePO;
import com.qiyu.mall.user.provider.utils.BeanCopyUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author idea
 * @data 2020/2/11
 */
@Service
@Slf4j
public class CommunityAssociateServiceImpl implements CommunityAssociateService {

    @Resource
    private CommunityAssociateDao communityAssociateDao;

    @Override
    public void incrIntegralById(int caId, Integer integral) {
        log.info("【CommunityAssociateService】更新合伙人积分,caId={},integral={}",caId,integral);
        communityAssociateDao.updateOneIntegral(caId,integral);
    }

    @Override
    public CommunityAssociateDTO getByAccountId(int accountId) {
        CommunityAssociatePO param=new CommunityAssociatePO();
        param.setAccountId(accountId);
        CommunityAssociatePO result = communityAssociateDao.selectOne(param);
        if(result==null){
            return null;
        }
        CommunityAssociateDTO communityAssociateDTO=new CommunityAssociateDTO();
        BeanUtils.copyProperties(result,communityAssociateDTO);
        return communityAssociateDTO;
    }

    @Override
    public CommunityAssociateDTO getById(int caId) {
        CommunityAssociatePO communityAssociatePO = communityAssociateDao.selectById(caId);
        if(communityAssociatePO==null){
            return null;
        }
        CommunityAssociateDTO communityAssociateDTO=new CommunityAssociateDTO();
        BeanUtils.copyProperties(communityAssociatePO,communityAssociateDTO);
        return communityAssociateDTO;
    }

    @Override
    public List<CommunityAssociateDTO> selectAll() {
        List<CommunityAssociatePO> communityAssociatePOS = communityAssociateDao.selectAll();
        List<CommunityAssociateDTO> communityAssociateDTOS=new ArrayList<>(communityAssociatePOS.size());
        communityAssociateDTOS = BeanCopyUtil.copyList(communityAssociatePOS,CommunityAssociateDTO.class);
        return communityAssociateDTOS;
    }
}
